<%@page pageEncoding = "utf-8" contentType = "text/html;charset=utf-8"%>

<%@taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%>

<script type="text/javascript">
window.onload = function () {
  bdate  = new Epoch('epoch_popup','popup',document.getElementById('bdate'));
};
</script>

<h2><fmt:message key = "form.addeditClient"/></h2>

<div class = "messages"><jsp:include page = "/messages.jsp"/></div>

<form action = "${sessionScope.alias}" method = "post" name = "clientAddForm">
<div id="box">
   <table class = "form">      
   	  <tr>
         <td class = "label"><fmt:message key = "form.login"/><span class="star">*</span></td>
         <td>
           <input name = "login" type = "text" maxlength="10" value = '<c:out value = "${clientBean.login}"/>'>
           <span class="error"><c:out value="${error.login}"/></span>
         </td>
      </tr>
      
      
     <c:if test="${sessionScope.role == 'admin'}"> 
      <tr>
         <td class = "label"><fmt:message key = "form.password"/><span class="star">*</span></td>
         <td>
           <input name = "password" type = "password" maxlength="10" value = '<c:out value = "${clientBean.password}"/>'>
           <span class="error"><c:out value="${error.password}"/></span>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "form.repassword"/><span class="star">*</span></td>
         <td>
           <input name = "repassword" type = "password" maxlength="10" value = '<c:out value = "${clientBean.rePassword}"/>'>
           <span class="error"><c:out value="${error.rePassword}"/></span>
         </td>
      </tr>      
      </c:if>
      
      <c:if test="${sessionScope.role == 'dispatcher'}">
        <tr>
        <td class = "label"><fmt:message key = "form.password"/><span class="star">*</span></td>
        <td>Пароль будет сгенерирован автоматически</td>
      </tr>   
      </c:if>

       
      <tr>
         <td class = "label"><fmt:message key = "client.lastName"/><span class="star">*</span></td>
         <td>
         	 <input name = "lastName" type = "text" maxlength="50" value = '<c:out value = "${clientBean.lastName}"/>'>
           <span class="error"><c:out value="${error.lastName}"/></span>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.firstName"/><span class="star">*</span></td>
         <td>
         	 <input name = "firstName" type = "text" maxlength="50" value = '<c:out value = "${clientBean.firstName}"/>'>
           <span class="error"><c:out value="${error.firstName}"/></span>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.middleName"/><span class="star">*</span></td>
         <td>
         	  <input name = "middleName" type = "text" maxlength="50" value = '<c:out value = "${clientBean.middleName}"/>'>
            <span class="error"><c:out value="${error.middleName}"/></span>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.birthday"/></td>
         <td>
            <input class="date" id="bdate" name = "birthday" type = "text" value = '<fmt:formatDate value="${clientBean.birthday}" pattern="dd.MM.yyyy"/>'>            
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.address"/></td>
         <td><input name = "address" type = "text" maxlength="100" value = '<c:out value = "${clientBean.address}"/>'></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.type"/><span class="star">*</span></td>
         <td>
            <select name="type_id">
              <c:forEach var = "clientType" items = "${clientTypesList}">
                <option value="${clientType.id}" ${clientType.id == clientBean.clientTypeId ? "selected" : ""}>${clientType.type}</option>
              </c:forEach>
            </select>            
            <span class="error"><c:out value="${error.type}"/></span>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.organization"/><span class="star">*</span></td>
         <td>
            <select id="organizationsList" name="organization_id">              
              <option value="0"><fmt:message key = "request.selectOrganization"/></option>
              <c:forEach var = "organization" items = "${organizationsList}">
                <option value="${organization.id}" ${organization.id==clientBean.organizationId ? "selected" : ""}>${organization.shortTitle}</option>
              </c:forEach>
            </select>            
            <span class="error"><c:out value="${error.organization}"/></span>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.department"/><span class="star">*</span></td>
         <td>
            <select name="department_id" id="departmentsList">
              <c:forEach var = "department" items = "${departmentsList}">
                <option value="${department.id}" ${department.id==clientBean.departmentId ? "selected" : ""}>${department.name}</option>
              </c:forEach>
            </select>            
            <span class="error"><c:out value="${error.department}"/></span>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.position"/></td>
         <td><input name = "pos" type = "text" maxlength="100" value = '<c:out value = "${clientBean.position}"/>'></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.tel1"/></td>
         <td><input name = "tel1" type = "text" maxlength="20" value = '<c:out value = "${clientBean.tel1}"/>'></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.tel2"/></td>
         <td><input name = "tel2" type = "text" maxlength="20" value = '<c:out value = "${clientBean.tel2}"/>'></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.tel3"/></td>
         <td><input name = "tel3" type = "text" maxlength="20" value = '<c:out value = "${clientBean.tel3}"/>'></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.email1"/><span class="star">*</span></td>
         <td>
         	 <input name = "email1" type = "text" maxlength="50" value = '<c:out value = "${clientBean.email1}"/>'>
           <span class="error"><c:out value="${error.email1}"/></span>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.email2"/></td>
         <td>
         	  <input name = "email2" type = "text" maxlength="50" value = '<c:out value = "${clientBean.email2}"/>'>
            <span class="error"><c:out value="${error.email2}"/></span>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.email3"/></td>
         <td>
         	  <input name = "email3" type = "text" maxlength="50" value = '<c:out value = "${clientBean.email3}"/>'>
         	  <span class="error"><c:out value="${error.email3}"/></span>
         </td>         	  	
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.www"/></td>
         <td><input name = "www" type = "text" maxlength="50" value = '<c:out value = "${clientBean.www}"/>'></td>
      </tr>
      
      <tr>
         <td class = "label">ICQ</td>
         <td><input name = "icq" type = "text" maxlength="10" value = '<c:out value = "${clientBean.icq}"/>'></td>
      </tr>                      

      <tr>
         <td class = "label"><fmt:message key = "client.notes"/></td>
         <td>
            <textarea name = "notes" rows="10" cols="50"><c:out value = "${clientBean.notes}"/></textarea>
         </td>
      </tr>
            

      <tr>
         <td class = "label"><input type="checkbox" name="donotify"/></td>
         <td>
            Отправить уведомление пользователю
         </td>
      </tr>
</table>
</div>

<input name = "id" type = "hidden" value='<c:out value = "${clientBean.id}"/>'>   
<input name = "_action" type = "hidden" value = "processClientForm">

<p>
   <span class="small">Обязательные для заполнения поля отмечены</span><span class="star">*</span>
</p>

<p>
  <input type = "submit" value = '<fmt:message key = "Command.save"/>'> или
  <a href = "javascript:reset();"><fmt:message key = "Command.reset"/></a> или
  <a href = "${sessionScope.alias}?_action=listClients"><fmt:message key = "Command.cancel"/></a>
</p>
</form>